#include "Ellipse.h"

Ellipse::Ellipse(){

}


Ellipse::Ellipse(const Ellipse &c1){
  
   (*this) = c1;
   
}

Ellipse::Ellipse(const int radiusX,const int radiusY,const MyDisplay &another){

   this->radiusX = radiusX;
   this->radiusY = radiusY;
   show = new MyDisplay(another);
   
//   show->createWindow( show->getWidth(), show->getHeight(), 0, 0);
//  show->createGC(0);

}

Ellipse::Ellipse(const int radiusX,const int radiusY,const int x ,const int y){

   this->radiusX = radiusX;
   this->radiusY = radiusY;
   this->x=x;
   this->y=y;
}





Ellipse::~Ellipse(){

}


bool Ellipse::draw(){
      
    long radiusSquareX,radiusSquareY;
    long twoRadiusSquareX,twoRadiusSquareY;
    int x1,y1;
    double decisionVar;
    double dx,dy;
    
    radiusSquareX = radiusX*radiusX;
    radiusSquareY = radiusY*radiusY;
    
    twoRadiusSquareX = 2* radiusSquareX;
    twoRadiusSquareY = 2* radiusSquareY;
    
    x1 = 0;
    y1 = radiusY;
    
    decisionVar = radiusSquareY - radiusSquareX* radiusY + (0.25 * radiusSquareX);
    
    dx = twoRadiusSquareY * x1;
    dy = twoRadiusSquareX * y1;
    
    
    
    do{
    
        cout<<"Inside 1st loop "<<endl;
         show->drawPoint(x1 + x,y1 + y);
	 show->drawPoint(-x1 + x,-y1 + y);
	 show->drawPoint(x1 + x,-y1 + y);
	 show->drawPoint(-x1 + x,y1 + y);
	 
	 
	 if(decisionVar < 0){
	 
	   ++x1;
	   y1 = y1;
	   dx = dx + twoRadiusSquareY;
	   decisionVar = decisionVar + dx + radiusSquareY;
	    
	 }else{
	   
	      x1++;
	      y1--;
	      
	    dx = dx + twoRadiusSquareY;
	    dy = dy - twoRadiusSquareX;
	    decisionVar = decisionVar + dx - dy + radiusSquareY;   
	 
	 }
    }while(dx < dy);
    
    
    
    decisionVar = radiusSquareY * (x1 + 0.5) * (x1 + 0.5) + radiusSquareX *(y1-1)*(y1-1) - radiusSquareX * radiusSquareY;
    
    
    do{
    
      cout<<"Inside 2nd loop "<<endl;
      show->drawPoint(x1+x,y1+y);
      show->drawPoint(-x1+x,-y1+y);
      show->drawPoint(x1+x,-y1+y);
      show->drawPoint(-x1+x,y1+y);
      
      if(decisionVar > 0){
      
          x1 = x1;
	  --y1;    
	  
	  dy = dy - twoRadiusSquareX;
	  decisionVar = decisionVar - dy + radiusSquareX;
	  
      }else{
      
          x1++;
	  y1--;
	  dy = dy - twoRadiusSquareX;
	  dx = dx + twoRadiusSquareY;
	  decisionVar = decisionVar + dx - dy + radiusSquareX;
     
      }
   
    }while(y1>0);
    
    
    
    
    
  //cout<<"END OF Ellipse DRAWING"  <<endl;
  //cout<<"###################################################"<<endl;
  
return true;
}



   bool Ellipse::draw(int x,int y){
   
       this -> x = x;
       this -> y = y;
       
       draw();
   }
     
   bool Ellipse::changeRadius(const int radiusX,const int radiusY){
         
       this->radiusX = radiusX;
       this->radiusY = radiusY;
          
       
   }
     
   bool Ellipse::draw(const int radiusX,const int radiusY,const int x,const int y){
   
       this->radiusX = radiusX;
       this->radiusY = radiusY;
       this->x = x;
       this->y = y; 
        
       draw();
   }
   
   
   
                                             
